﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Distrackting.BusinessLayer;
using Distrackting.DataLayer;
using Distrackting.PresentationLayer;
using System.Collections.Generic;
using System.Text;

namespace Distrackting.PresentationLayer
{
    public partial class Main : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Not logged
            if (Session["user_guid"] == null)
            {
                AdicPercHyperLink.Visible = false;
                UtilHyperLink.Visible = false;
            }
            else
            {
                try
                {
                    Guid user_guid = new Guid(Session["user_guid"].ToString());
                    int user_level = Convert.ToInt32(Session["user_level"]);
                    
                    //ISTO AQUI ESTA NOJENTO MAS A MELHOR MANEIRA DE RESOLVER ERA COM UM ROLEMANAGER/PROVIDER
                    switch (user_level)
                    {
                        //NAO REGISTADO
                        case 10:    AdicPercHyperLink.Visible = false;
                                    UtilHyperLink.Visible = false; 
                                    break;

                        //REGISTADO
                        case 30:    AdicPercHyperLink.Visible = true;
                                    UtilHyperLink.Visible = false;
                                    break;

                        //MODERADOR
                        case 70:    AdicPercHyperLink.Visible = true;
                                    UtilHyperLink.Visible = false;
                                    break;

                        //ADMINISTRADOR
                        case 100:   UtilHyperLink.Visible = true;
                                    AdicPercHyperLink.Visible = true;
                                    break;
                        default: break;
                    }

                }
                catch (Exception ex)
                {
                    Mensagens.AdicionarErro(ex.Message);
                }
            }
        }
        

        public String mensagens()
        {
            List<String> lista = Mensagens.mostrarMensagens();

            if (lista != null)
            {
                StringBuilder sb = new StringBuilder();
                int count = lista.Count;
                int i = 0;

                foreach (String s in lista)
                {
                    sb.Append(s);
                    if (i < count - 1) sb.Append("<br>");
                    i++;
                }

                return "<div class='mensagens'>" + sb.ToString() + "</div>";

            }
            else return "";
        }

        public String erros()
        {
            List<String> lista = Mensagens.mostrarErros();

            if (lista != null)
            {
                StringBuilder sb = new StringBuilder();
                int count = lista.Count;
                int i = 0;

                foreach (String s in lista)
                {
                    sb.Append(s);
                    if (i < count - 1) sb.Append("<br>");
                    i++;
                }

                return "<div class='erros'>" + sb.ToString() + "</div>";

            }
            else return "";
        }

        public String debugs()
        {
            List<String> lista = Mensagens.mostrarDebugs();

            if (lista != null)
            {
                StringBuilder sb = new StringBuilder();
                int count = lista.Count;
                int i = 0;

                foreach (String s in lista)
                {
                    sb.Append(s);
                    if (i < count - 1) sb.Append("<br>");
                    i++;
                }

                return "<div class='debugs'>" + sb.ToString() + "</div>";

            }
            else return "";
        }

    }
}
